<template>
  <uv-navbar
    class="navbar-class"
    :leftIconColor="leftIconColor"
    :bgColor="bgColor"
    :placeholder="placeholder"
    v-bind="$attrs"
    @leftClick="back"
  >
    <template v-slot:center>
      <slot v-if="isSlot"></slot>
      <text v-else :style="headerStyle" class="header-class">{{ text }}</text>
    </template>
  </uv-navbar>
</template>
<script lang="js" setup>
import { tabBar } from '@/pages.json'
const props = defineProps({
  isSlot: {
    type: Boolean,
    default: false,
  },
  headerStyle: {
    type: Object,
    default: () => {},
  },
  leftIconColor: {
    type: String,
    default: '#ffffff',
  },
  bgColor: {
    type: String,
    default: '#E50038',
  },
  placeholder: {
    type: Boolean,
    default: true,
  },
  text: {
    type: String,
    default: '',
  },
  backPath: {
    type: String,
    default: '/pages/home/index',
  },
})

const back = () => {
  const tabBarList = tabBar.list
  const pages = getCurrentPages()
  if (pages.length > 1) {
    uni.navigateBack()
  } else if (tabBarList.some((o) => '/' + o.pagePath === props.backPath)) {
    uni.switchTab({
      url: props.backPath,
    })
  } else {
    uni.reLaunch({
      url: props.backPath,
    })
  }
}
</script>
<style lang="scss">
.header-class {
  font-size: 32rpx;
  color: #ffffff;
}
</style>
